//应用初始化
import 'dart:async';

import 'package:common_utils/common_utils.dart';
import 'package:flutter/cupertino.dart';

import '../utils/log.dart';
import 'default_app.dart';

class AppInit{
  static void run(){
    //捕获异常
    catchException(() => DefaultApp.run());
  }

  ///异常捕获处理
  static void catchException<T>(T Function() callback) {
    //捕获异常的回调
    FlutterError.onError = (FlutterErrorDetails details) {
      reportErrorAndLog(details);
    };
    runZoned<Future<void>>(
      () async {
        callback();
      },onError: (error, stackTrace){
        Log.e(error);
        //跳转到error
      }
    );
  }

  //上报错误和日志逻辑
  static void reportErrorAndLog(FlutterErrorDetails details) {
    //日志打印
    Log.e(details);
    //跳转
  }

}